<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="dao.GetDate"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="css/allcss.css" rel="stylesheet" type="text/css"/>
        <link rel="shortcut icon"  href="image/icon6.ico" type="image/x-icon" /> 
        <script src="./script/jquery.js" type="text/javascript"></script>
        <style>
            #op6{
                color:#00aeec;
            }
        </style>
        <title>SYN</title>
    </head>
    <body>
        <div id="aside">
            <img id="icon" src="./image/icon6.png">
            <div id="p1">管理员界面</div>         
        </div>
        <div id="main">
            <div id="list"><div id="op1" class="options">全部预约</div><div  id="op2" class="options">未审核</div><div  id="op3" class="options">已审核</div>
                <div  id="op4" class="options">地点管理</div><div  id="op5" class="options">地点上新</div><div  id="op6" class="options">数据库管理</div>
                <div  id="op7" class="options">学生信用度</div><div  id="op8" class="options">申诉回复</div>
            </div>
            <div id="content">
                <div class="syns">
                    <%
                        out.print("<div class='syn_text'>数据库内最早时间:" + GetDate.getOldDate() + "</div><div class='syn_text'>现在时间:" + GetDate.getNowDate());
                        long d = GetDate.getDistance();
                        out.print("</div><div class='syn_text' id='dis'  value='" + d + "'>距离" + d + "天</div>");
                        if (d < 3 && d != 0) {
                            out.println("<button id='syn_button3' onclick='add(event)'>3日内同步</button>");
                        } else if (d >= 3) {
                            out.print("<button id='syn_button1' onclick='add(event)'>自动同步</button><div id='selectedDateDiv'><select id='selectedDate'>");
                            for (int i = -9; i < 10; i++) {
                                out.print("<option value='" + (i + d) + "'>" + GetDate.getFutureDate(i) + "</option>");
                            }
                            out.println("</select></div><button id='syn_button2' onclick='add(event)'>手动同步</button>");
                        }
                        out.print("<button id='syn_button4' onclick='add(event)'>删除过时信息</button>");
                    %>
                </div>
            </div>
        </div>
        <script>
            function add(event) {
                var id = event.target.id;
                if (confirm("是否操作")) {
                    switch (id) {
                        case "syn_button1":
                            $.get("./Servlet/synServlet?type=1&dis=" + $("#dis").attr("value"), popup);
                            break;
                        case "syn_button2":
                            alert("增加" + $("#selectedDate option:selected").val() + "天");
                            $.get("./Servlet/synServlet?type=1&dis=" + $("#selectedDate option:selected").val(), popup);
                            break;
                        case "syn_button3":
                            $.get("./Servlet/synServlet?type=0", popup);
                            break;
                        case "syn_button4":
                            $.get("./Servlet/deleteServlet", popup);
                            break;
                    }
                    window.location.reload();
                }
            }
            function popup(data, status) {
                if (status) {
                    if (data !== "-1")
                        alert("成功");
                    else
                        alert("失败");
                }
            }
        </script>
        <script src="script/button.js" type="text/javascript"></script>
    </body>
</html>
